package net.nshc.kwkim.mycalc.buttonlistener;

import net.nshc.kwkim.mycalc.*;
import android.app.*;
import android.content.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class CalcButtonClickListener implements OnClickListener {
	protected Context context = null;
	protected EditText editTextInput = null;
	protected TextView TextViewDisplay = null;
	protected boolean bLocation = false;

	public CalcButtonClickListener(Context context) {
		this.context = context;
		this.editTextInput
		= (EditText)((Activity)context).findViewById(R.id.input);
		this.TextViewDisplay
		= (TextView)((Activity)context).findViewById(R.id.display);
	}
	
	public CalcButtonClickListener(Context context, boolean abLocation){
		this.context = context;
		this.editTextInput
		= (EditText)((Activity)context).findViewById(R.id.input);
		this.TextViewDisplay
		= (TextView)((Activity)context).findViewById(R.id.display);
		this.bLocation = abLocation;
	}

	public void onClick(View v) {
		resultString(editTextInput, TextViewDisplay);
	}
	
	protected void resultString(EditText editTextinput, TextView TextViewdisplay) {
		PostFixExp post = new PostFixExp();
		StringBuilder textFromEditText = new StringBuilder(editTextinput.getText().toString().trim());
		String Value = new String();
		Double Result = null;

		if (textFromEditText != null) {
			
			Value  = post.infixToPostfix(Value);
			Result = post.result(Value);
			TextViewdisplay.append(textFromEditText+"="+String.format("%.4f", Result));
			editTextinput.setText(String.format("%.4f", Result));
		}
	}

	
}
